import Cookies from 'js-cookie'

const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('SMS_sidebarStatus')
    },
    oldUid:"", //在该页卡登录时的用户id
    optionId:localStorage.getItem('optionId'),
    orgId:localStorage.getItem('orgId'),//||localStorage.setItem('orgId',1)||1,//机构id，运管系统中表示母品牌，采购平台中表示经销商id
    platId:localStorage.getItem('platId')||localStorage.setItem('platId',1)||1,//1为运管系统，2为平台运维，3为采购平台
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('SMS_sidebarStatus', 1)
      } else {
        Cookies.set('SMS_sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    // getoptionId(id){
    //   state.optionId = id
    //   sessionStorage.setItem('optionId',state.optionId)
    // }
    updateoldUid(state,id){
        state.oldUid = id
    },
    updateopid(state,id){
        state.optionId = id
        localStorage.setItem('optionId',state.optionId)
    },
    updateorgid(state,id){
      state.orgId = id
      localStorage.setItem('orgId',state.orgId)
    },
    updateplatid(state,id){
      state.platId = id
      localStorage.setItem('platId',state.platId)
    }
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    },

  }
}

export default app
